#! /usr/bin/env python
# coding=utf-8



import os
import shutil
import sys
import argparse


parser = argparse.ArgumentParser(
    description='''
    # 给定一个基因列表
	# 从一个interprotscan 统计各个domain 出现的次数
    用法:
    get_inter_domain_from_list.py -i target -t Amel.fa.tsv
    ''')

parser.add_argument('-i',
                help='必须给定，输入的基因列表')


parser.add_argument('-t',
                help='必须给定，输入的tsv文件')


args = parser.parse_args()

if not args.i or not args.t:
    parser.print_help()
    sys.exit()



infile = args.i

tsv_file = args.t



target = []

with open(infile) as fila:
	for i in fila:
		target.append(i.strip())

dic = {}

name_dic = {}


with open(tsv_file) as fila:
	for i in fila:
		t = i.strip().split('\t')
		if len(t)>5 and t[0] in target:
			name_dic[t[4]] = t[5]
			if t[4] not in dic:
				dic[t[4]] = 1
			else:
				dic[t[4]] += 1


key_order = sorted(list(dic.keys()), key=lambda x:-dic[x])

for i in key_order:
	print(str(i)+'\t'+str(name_dic[i])+'\t'+str(dic[i]))